home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / os.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  26KB  |  855 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """OS routines for Mac, NT, or Posix depending on what system we're on.
  5.  
  6. This exports:
  7.   - all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc.
  8.   - os.path is one of the modules posixpath, or ntpath
  9.   - os.name is 'posix', 'nt', 'os2', 'ce' or 'riscos'
  10.   - os.curdir is a string representing the current directory ('.' or ':')
  11.   - os.pardir is a string representing the parent directory ('..' or '::')
  12.   - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\\\')
  13.   - os.extsep is the extension separator ('.' or '/')
  14.   - os.altsep is the alternate pathname separator (None or '/')
  15.   - os.pathsep is the component separator used in $PATH etc
  16.   - os.linesep is the line separator in text files ('\\r' or '\\n' or '\\r\\n')
  17.   - os.defpath is the default search path for executables
  18.   - os.devnull is the file path of the null device ('/dev/null', etc.)
  19.  
  20. Programs that import and use 'os' stand a better chance of being
  21. portable between different platforms.  Of course, they must then
  22. only use functions that are defined by all platforms (e.g., unlink
  23. and opendir), and leave all pathname manipulation to os.path
  24. (e.g., split and join).
  25. """
  26. import sys
  27. import errno
  28. _names = sys.builtin_module_names
  29. __all__ = [
  30.     'altsep',
  31.     'curdir',
  32.     'pardir',
  33.     'sep',
  34.     'extsep',
  35.     'pathsep',
  36.     'linesep',
  37.     'defpath',
  38.     'name',
  39.     'path',
  40.     'devnull',
  41.     'SEEK_SET',
  42.     'SEEK_CUR',
  43.     'SEEK_END']
  44.  
  45. def _get_exports_list(module):
  46.     
  47.     try:
  48.         return list(module.__all__)
  49.     except AttributeError:
  50.         return _[1]
  51.         []
  52.  
  53.  
  54. if 'posix' in _names:
  55.     name = 'posix'
  56.     linesep = '\n'
  57.     from posix import *
  58.     
  59.     try:
  60.         from posix import _exit
  61.     except ImportError:
  62.         pass
  63.  
  64.     import posixpath as path
  65.     import posix
  66.     __all__.extend(_get_exports_list(posix))
  67.     del posix
  68. elif 'nt' in _names:
  69.     name = 'nt'
  70.     linesep = '\r\n'
  71.     from nt import *
  72.     
  73.     try:
  74.         from nt import _exit
  75.     except ImportError:
  76.         pass
  77.  
  78.     import ntpath as path
  79.     import nt
  80.     __all__.extend(_get_exports_list(nt))
  81.     del nt
  82. elif 'os2' in _names:
  83.     name = 'os2'
  84.     linesep = '\r\n'
  85.     from os2 import *
  86.     
  87.     try:
  88.         from os2 import _exit
  89.     except ImportError:
  90.         pass
  91.  
  92.     if sys.version.find('EMX GCC') == -1:
  93.         import ntpath as path
  94.     else:
  95.         import os2emxpath as path
  96.         from _emx_link import link
  97.     import os2
  98.     __all__.extend(_get_exports_list(os2))
  99.     del os2
  100. elif 'ce' in _names:
  101.     name = 'ce'
  102.     linesep = '\r\n'
  103.     from ce import *
  104.     
  105.     try:
  106.         from ce import _exit
  107.     except ImportError:
  108.         pass
  109.  
  110.     import ntpath as path
  111.     import ce
  112.     __all__.extend(_get_exports_list(ce))
  113.     del ce
  114. elif 'riscos' in _names:
  115.     name = 'riscos'
  116.     linesep = '\n'
  117.     from riscos import *
  118.     
  119.     try:
  120.         from riscos import _exit
  121.     except ImportError:
  122.         pass
  123.  
  124.     import riscospath as path
  125.     import riscos
  126.     __all__.extend(_get_exports_list(riscos))
  127.     del riscos
  128. else:
  129.     raise ImportError, 'no os specific module found'
  130. sys.modules['os.path'] = 'posix' in _names
  131. from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull
  132. del _names
  133. SEEK_SET = 0
  134. SEEK_CUR = 1
  135. SEEK_END = 2
  136.  
  137. def makedirs(name, mode = 511):
  138.     '''makedirs(path [, mode=0777])
  139.  
  140.     Super-mkdir; create a leaf directory and all intermediate ones.
  141.     Works like mkdir, except that any intermediate path segment (not
  142.     just the rightmost) will be created if it does not exist.  This is
  143.     recursive.
  144.  
  145.     '''
  146.     (head, tail) = path.split(name)
  147.     if not tail:
  148.         (head, tail) = path.split(head)
  149.     
  150.     if head and tail and not path.exists(head):
  151.         
  152.         try:
  153.             makedirs(head, mode)
  154.         except OSError:
  155.             e = None
  156.             if e.errno != errno.EEXIST:
  157.                 raise 
  158.             e.errno != errno.EEXIST
  159.  
  160.         if tail == curdir:
  161.             return None
  162.     
  163.     mkdir(name, mode)
  164.  
  165.  
  166. def removedirs(name):
  167.     '''removedirs(path)
  168.  
  169.     Super-rmdir; remove a leaf directory and all empty intermediate
  170.     ones.  Works like rmdir except that, if the leaf directory is
  171.     successfully removed, directories corresponding to rightmost path
  172.     segments will be pruned away until either the whole path is
  173.     consumed or an error occurs.  Errors during this latter phase are
  174.     ignored -- they generally mean that a directory was not empty.
  175.  
  176.     '''
  177.     rmdir(name)
  178.     (head, tail) = path.split(name)
  179.     if not tail:
  180.         (head, tail) = path.split(head)
  181.     
  182.     while head and tail:
  183.         
  184.         try:
  185.             rmdir(head)
  186.         except error:
  187.             break
  188.  
  189.         (head, tail) = path.split(head)
  190.  
  191.  
  192. def renames(old, new):
  193.     '''renames(old, new)
  194.  
  195.     Super-rename; create directories as necessary and delete any left
  196.     empty.  Works like rename, except creation of any intermediate
  197.     directories needed to make the new pathname good is attempted
  198.     first.  After the rename, directories corresponding to rightmost
  199.     path segments of the old name will be pruned way until either the
  200.     whole path is consumed or a nonempty directory is found.
  201.  
  202.     Note: this function can fail with the new directory structure made
  203.     if you lack permissions needed to unlink the leaf directory or
  204.     file.
  205.  
  206.     '''
  207.     (head, tail) = path.split(new)
  208.     if head and tail and not path.exists(head):
  209.         makedirs(head)
  210.     
  211.     rename(old, new)
  212.     (head, tail) = path.split(old)
  213.     if head and tail:
  214.         
  215.         try:
  216.             removedirs(head)
  217.         except error:
  218.             pass
  219.         except:
  220.             None<EXCEPTION MATCH>error
  221.         
  222.  
  223.     None<EXCEPTION MATCH>error
  224.  
  225. __all__.extend([
  226.     'makedirs',
  227.     'removedirs',
  228.     'renames'])
  229.  
  230. def walk(top, topdown = True, onerror = None, followlinks = False):
  231.     '''Directory tree generator.
  232.  
  233.     For each directory in the directory tree rooted at top (including top
  234.     itself, but excluding \'.\' and \'..\'), yields a 3-tuple
  235.  
  236.         dirpath, dirnames, filenames
  237.  
  238.     dirpath is a string, the path to the directory.  dirnames is a list of
  239.     the names of the subdirectories in dirpath (excluding \'.\' and \'..\').
  240.     filenames is a list of the names of the non-directory files in dirpath.
  241.     Note that the names in the lists are just names, with no path components.
  242.     To get a full path (which begins with top) to a file or directory in
  243.     dirpath, do os.path.join(dirpath, name).
  244.  
  245.     If optional arg \'topdown\' is true or not specified, the triple for a
  246.     directory is generated before the triples for any of its subdirectories
  247.     (directories are generated top down).  If topdown is false, the triple
  248.     for a directory is generated after the triples for all of its
  249.     subdirectories (directories are generated bottom up).
  250.  
  251.     When topdown is true, the caller can modify the dirnames list in-place
  252.     (e.g., via del or slice assignment), and walk will only recurse into the
  253.     subdirectories whose names remain in dirnames; this can be used to prune
  254.     the search, or to impose a specific order of visiting.  Modifying
  255.     dirnames when topdown is false is ineffective, since the directories in
  256.     dirnames have already been generated by the time dirnames itself is
  257.     generated.
  258.  
  259.     By default errors from the os.listdir() call are ignored.  If
  260.     optional arg \'onerror\' is specified, it should be a function; it
  261.     will be called with one argument, an os.error instance.  It can
  262.     report the error to continue with the walk, or raise the exception
  263.     to abort the walk.  Note that the filename is available as the
  264.     filename attribute of the exception object.
  265.  
  266.     By default, os.walk does not follow symbolic links to subdirectories on
  267.     systems that support them.  In order to get this functionality, set the
  268.     optional argument \'followlinks\' to true.
  269.  
  270.     Caution:  if you pass a relative pathname for top, don\'t change the
  271.     current working directory between resumptions of walk.  walk never
  272.     changes the current directory, and assumes that the client doesn\'t
  273.     either.
  274.  
  275.     Example:
  276.  
  277.     import os
  278.     from os.path import join, getsize
  279.     for root, dirs, files in os.walk(\'python/Lib/email\'):
  280.         print root, "consumes",
  281.         print sum([getsize(join(root, name)) for name in files]),
  282.         print "bytes in", len(files), "non-directory files"
  283.         if \'CVS\' in dirs:
  284.             dirs.remove(\'CVS\')  # don\'t visit CVS directories
  285.     '''
  286.     join = join
  287.     isdir = isdir
  288.     islink = islink
  289.     import os.path
  290.     
  291.     try:
  292.         names = listdir(top)
  293.     except error:
  294.         err = None
  295.         if onerror is not None:
  296.             onerror(err)
  297.         
  298.         return None
  299.  
  300.     dirs = []
  301.     nondirs = []
  302.     for name in names:
  303.         if isdir(join(top, name)):
  304.             dirs.append(name)
  305.             continue
  306.         nondirs.append(name)
  307.     
  308.     if topdown:
  309.         yield (top, dirs, nondirs)
  310.     
  311.     for name in dirs:
  312.         path = join(top, name)
  313.         if followlinks or not islink(path):
  314.             for x in walk(path, topdown, onerror, followlinks):
  315.                 yield x
  316.             
  317.     
  318.     if not topdown:
  319.         yield (top, dirs, nondirs)
  320.     
  321.  
  322. __all__.append('walk')
  323.  
  324. try:
  325.     environ
  326. except NameError:
  327.     environ = { }
  328.  
  329.  
  330. def execl(file, *args):
  331.     '''execl(file, *args)
  332.  
  333.     Execute the executable file with argument list args, replacing the
  334.     current process. '''
  335.     execv(file, args)
  336.  
  337.  
  338. def execle(file, *args):
  339.     '''execle(file, *args, env)
  340.  
  341.     Execute the executable file with argument list args and
  342.     environment env, replacing the current process. '''
  343.     env = args[-1]
  344.     execve(file, args[:-1], env)
  345.  
  346.  
  347. def execlp(file, *args):
  348.     '''execlp(file, *args)
  349.  
  350.     Execute the executable file (which is searched for along $PATH)
  351.     with argument list args, replacing the current process. '''
  352.     execvp(file, args)
  353.  
  354.  
  355. def execlpe(file, *args):
  356.     '''execlpe(file, *args, env)
  357.  
  358.     Execute the executable file (which is searched for along $PATH)
  359.     with argument list args and environment env, replacing the current
  360.     process. '''
  361.     env = args[-1]
  362.     execvpe(file, args[:-1], env)
  363.  
  364.  
  365. def execvp(file, args):
  366.     '''execp(file, args)
  367.  
  368.     Execute the executable file (which is searched for along $PATH)
  369.     with argument list args, replacing the current process.
  370.     args may be a list or tuple of strings. '''
  371.     _execvpe(file, args)
  372.  
  373.  
  374. def execvpe(file, args, env):
  375.     '''execvpe(file, args, env)
  376.  
  377.     Execute the executable file (which is searched for along $PATH)
  378.     with argument list args and environment env , replacing the
  379.     current process.
  380.     args may be a list or tuple of strings. '''
  381.     _execvpe(file, args, env)
  382.  
  383. __all__.extend([
  384.     'execl',
  385.     'execle',
  386.     'execlp',
  387.     'execlpe',
  388.     'execvp',
  389.     'execvpe'])
  390.  
  391. def _execvpe(file, args, env = None):
  392.     if env is not None:
  393.         func = execve
  394.         argrest = (args, env)
  395.     else:
  396.         func = execv
  397.         argrest = (args,)
  398.         env = environ
  399.     (head, tail) = path.split(file)
  400.     if head:
  401.         func(file, *argrest)
  402.         return None
  403.     if 'PATH' in env:
  404.         envpath = env['PATH']
  405.     else:
  406.         envpath = defpath
  407.     PATH = envpath.split(pathsep)
  408.     saved_exc = None
  409.     saved_tb = None
  410.     for dir in PATH:
  411.         fullname = path.join(dir, file)
  412.         
  413.         try:
  414.             func(fullname, *argrest)
  415.         continue
  416.         except error:
  417.             e = None
  418.             tb = sys.exc_info()[2]
  419.             if e.errno != errno.ENOENT and e.errno != errno.ENOTDIR and saved_exc is None:
  420.                 saved_exc = e
  421.                 saved_tb = tb
  422.             
  423.             saved_exc is None
  424.         
  425.  
  426.     
  427.     if saved_exc:
  428.         raise error, saved_exc, saved_tb
  429.     saved_exc
  430.     raise error, e, tb
  431.  
  432.  
  433. try:
  434.     putenv
  435. except NameError:
  436.     pass
  437.  
  438. import UserDict
  439. if name in ('os2', 'nt'):
  440.     
  441.     def unsetenv(key):
  442.         putenv(key, '')
  443.  
  444.  
  445. if name == 'riscos':
  446.     from riscosenviron import _Environ
  447. elif name in ('os2', 'nt'):
  448.     
  449.     class _Environ(UserDict.IterableUserDict):
  450.         
  451.         def __init__(self, environ):
  452.             UserDict.UserDict.__init__(self)
  453.             data = self.data
  454.             for k, v in environ.items():
  455.                 data[k.upper()] = v
  456.             
  457.  
  458.         
  459.         def __setitem__(self, key, item):
  460.             putenv(key, item)
  461.             self.data[key.upper()] = item
  462.  
  463.         
  464.         def __getitem__(self, key):
  465.             return self.data[key.upper()]
  466.  
  467.         
  468.         try:
  469.             unsetenv
  470.         except NameError:
  471.             
  472.             def __delitem__(self, key):
  473.                 del self.data[key.upper()]
  474.  
  475.  
  476.         
  477.         def __delitem__(self, key):
  478.             unsetenv(key)
  479.             del self.data[key.upper()]
  480.  
  481.         
  482.         def clear(self):
  483.             for key in self.data.keys():
  484.                 unsetenv(key)
  485.                 del self.data[key]
  486.             
  487.  
  488.         
  489.         def pop(self, key, *args):
  490.             unsetenv(key)
  491.             return self.data.pop(key.upper(), *args)
  492.  
  493.         
  494.         def has_key(self, key):
  495.             return key.upper() in self.data
  496.  
  497.         
  498.         def __contains__(self, key):
  499.             return key.upper() in self.data
  500.  
  501.         
  502.         def get(self, key, failobj = None):
  503.             return self.data.get(key.upper(), failobj)
  504.  
  505.         
  506.         def update(self, dict = None, **kwargs):
  507.             if dict:
  508.                 
  509.                 try:
  510.                     keys = dict.keys()
  511.                 except AttributeError:
  512.                     for k, v in dict:
  513.                         self[k] = v
  514.                     
  515.  
  516.                 for k in keys:
  517.                     self[k] = dict[k]
  518.                 
  519.             
  520.             if kwargs:
  521.                 self.update(kwargs)
  522.             
  523.  
  524.         
  525.         def copy(self):
  526.             return dict(self)
  527.  
  528.  
  529. else:
  530.     
  531.     class _Environ(UserDict.IterableUserDict):
  532.         
  533.         def __init__(self, environ):
  534.             UserDict.UserDict.__init__(self)
  535.             self.data = environ
  536.  
  537.         
  538.         def __setitem__(self, key, item):
  539.             putenv(key, item)
  540.             self.data[key] = item
  541.  
  542.         
  543.         def update(self, dict = None, **kwargs):
  544.             if dict:
  545.                 
  546.                 try:
  547.                     keys = dict.keys()
  548.                 except AttributeError:
  549.                     for k, v in dict:
  550.                         self[k] = v
  551.                     
  552.  
  553.                 for k in keys:
  554.                     self[k] = dict[k]
  555.                 
  556.             
  557.             if kwargs:
  558.                 self.update(kwargs)
  559.             
  560.  
  561.         
  562.         try:
  563.             unsetenv
  564.         except NameError:
  565.             pass
  566.  
  567.         
  568.         def __delitem__(self, key):
  569.             unsetenv(key)
  570.             del self.data[key]
  571.  
  572.         
  573.         def clear(self):
  574.             for key in self.data.keys():
  575.                 unsetenv(key)
  576.                 del self.data[key]
  577.             
  578.  
  579.         
  580.         def pop(self, key, *args):
  581.             unsetenv(key)
  582.             return self.data.pop(key, *args)
  583.  
  584.         
  585.         def copy(self):
  586.             return dict(self)
  587.  
  588.  
  589. environ = _Environ(environ)
  590.  
  591. def getenv(key, default = None):
  592.     """Get an environment variable, return None if it doesn't exist.
  593.     The optional second argument can specify an alternate default."""
  594.     return environ.get(key, default)
  595.  
  596. __all__.append('getenv')
  597.  
  598. def _exists(name):
  599.     
  600.     try:
  601.         eval(name)
  602.         return True
  603.     except NameError:
  604.         return False
  605.  
  606.  
  607. if _exists('fork') and not _exists('spawnv') and _exists('execv'):
  608.     P_WAIT = 0
  609.     P_NOWAIT = P_NOWAITO = 1
  610.     
  611.     def _spawnvef(mode, file, args, env, func):
  612.         pid = fork()
  613.         if not pid:
  614.             
  615.             try:
  616.                 if env is None:
  617.                     func(file, args)
  618.                 else:
  619.                     func(file, args, env)
  620.             _exit(127)
  621.  
  622.         elif mode == P_NOWAIT:
  623.             return pid
  624.         while None:
  625.             (wpid, sts) = waitpid(pid, 0)
  626.             if WIFSTOPPED(sts):
  627.                 continue
  628.                 continue
  629.             if WIFSIGNALED(sts):
  630.                 return -WTERMSIG(sts)
  631.             if WIFEXITED(sts):
  632.                 return WEXITSTATUS(sts)
  633.             raise error, 'Not stopped, signaled or exited???'
  634.             continue
  635.             return None
  636.  
  637.     
  638.     def spawnv(mode, file, args):
  639.         """spawnv(mode, file, args) -> integer
  640.  
  641. Execute file with arguments from args in a subprocess.
  642. If mode == P_NOWAIT return the pid of the process.
  643. If mode == P_WAIT return the process's exit code if it exits normally;
  644. otherwise return -SIG, where SIG is the signal that killed it. """
  645.         return _spawnvef(mode, file, args, None, execv)
  646.  
  647.     
  648.     def spawnve(mode, file, args, env):
  649.         """spawnve(mode, file, args, env) -> integer
  650.  
  651. Execute file with arguments from args in a subprocess with the
  652. specified environment.
  653. If mode == P_NOWAIT return the pid of the process.
  654. If mode == P_WAIT return the process's exit code if it exits normally;
  655. otherwise return -SIG, where SIG is the signal that killed it. """
  656.         return _spawnvef(mode, file, args, env, execve)
  657.  
  658.     
  659.     def spawnvp(mode, file, args):
  660.         """spawnvp(mode, file, args) -> integer
  661.  
  662. Execute file (which is looked for along $PATH) with arguments from
  663. args in a subprocess.
  664. If mode == P_NOWAIT return the pid of the process.
  665. If mode == P_WAIT return the process's exit code if it exits normally;
  666. otherwise return -SIG, where SIG is the signal that killed it. """
  667.         return _spawnvef(mode, file, args, None, execvp)
  668.  
  669.     
  670.     def spawnvpe(mode, file, args, env):
  671.         """spawnvpe(mode, file, args, env) -> integer
  672.  
  673. Execute file (which is looked for along $PATH) with arguments from
  674. args in a subprocess with the supplied environment.
  675. If mode == P_NOWAIT return the pid of the process.
  676. If mode == P_WAIT return the process's exit code if it exits normally;
  677. otherwise return -SIG, where SIG is the signal that killed it. """
  678.         return _spawnvef(mode, file, args, env, execvpe)
  679.  
  680.  
  681. if _exists('spawnv'):
  682.     
  683.     def spawnl(mode, file, *args):
  684.         """spawnl(mode, file, *args) -> integer
  685.  
  686. Execute file with arguments from args in a subprocess.
  687. If mode == P_NOWAIT return the pid of the process.
  688. If mode == P_WAIT return the process's exit code if it exits normally;
  689. otherwise return -SIG, where SIG is the signal that killed it. """
  690.         return spawnv(mode, file, args)
  691.  
  692.     
  693.     def spawnle(mode, file, *args):
  694.         """spawnle(mode, file, *args, env) -> integer
  695.  
  696. Execute file with arguments from args in a subprocess with the
  697. supplied environment.
  698. If mode == P_NOWAIT return the pid of the process.
  699. If mode == P_WAIT return the process's exit code if it exits normally;
  700. otherwise return -SIG, where SIG is the signal that killed it. """
  701.         env = args[-1]
  702.         return spawnve(mode, file, args[:-1], env)
  703.  
  704.     __all__.extend([
  705.         'spawnv',
  706.         'spawnve',
  707.         'spawnl',
  708.         'spawnle'])
  709.  
  710. if _exists('spawnvp'):
  711.     
  712.     def spawnlp(mode, file, *args):
  713.         """spawnlp(mode, file, *args) -> integer
  714.  
  715. Execute file (which is looked for along $PATH) with arguments from
  716. args in a subprocess with the supplied environment.
  717. If mode == P_NOWAIT return the pid of the process.
  718. If mode == P_WAIT return the process's exit code if it exits normally;
  719. otherwise return -SIG, where SIG is the signal that killed it. """
  720.         return spawnvp(mode, file, args)
  721.  
  722.     
  723.     def spawnlpe(mode, file, *args):
  724.         """spawnlpe(mode, file, *args, env) -> integer
  725.  
  726. Execute file (which is looked for along $PATH) with arguments from
  727. args in a subprocess with the supplied environment.
  728. If mode == P_NOWAIT return the pid of the process.
  729. If mode == P_WAIT return the process's exit code if it exits normally;
  730. otherwise return -SIG, where SIG is the signal that killed it. """
  731.         env = args[-1]
  732.         return spawnvpe(mode, file, args[:-1], env)
  733.  
  734.     __all__.extend([
  735.         'spawnvp',
  736.         'spawnvpe',
  737.         'spawnlp',
  738.         'spawnlpe'])
  739.  
  740. if _exists('fork'):
  741.     if not _exists('popen2'):
  742.         
  743.         def popen2(cmd, mode = 't', bufsize = -1):
  744.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  745.             may be a sequence, in which case arguments will be passed directly to
  746.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  747.             is a string it will be passed to the shell (as with os.system()). If
  748.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  749.             file objects (child_stdin, child_stdout) are returned."""
  750.             import warnings as warnings
  751.             msg = 'os.popen2 is deprecated.  Use the subprocess module.'
  752.             warnings.warn(msg, DeprecationWarning, stacklevel = 2)
  753.             import subprocess as subprocess
  754.             PIPE = subprocess.PIPE
  755.             p = subprocess.Popen(cmd, shell = isinstance(cmd, basestring), bufsize = bufsize, stdin = PIPE, stdout = PIPE, close_fds = True)
  756.             return (p.stdin, p.stdout)
  757.  
  758.         __all__.append('popen2')
  759.     
  760.     if not _exists('popen3'):
  761.         
  762.         def popen3(cmd, mode = 't', bufsize = -1):
  763.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  764.             may be a sequence, in which case arguments will be passed directly to
  765.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  766.             is a string it will be passed to the shell (as with os.system()). If
  767.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  768.             file objects (child_stdin, child_stdout, child_stderr) are returned."""
  769.             import warnings
  770.             msg = 'os.popen3 is deprecated.  Use the subprocess module.'
  771.             warnings.warn(msg, DeprecationWarning, stacklevel = 2)
  772.             import subprocess
  773.             PIPE = subprocess.PIPE
  774.             p = subprocess.Popen(cmd, shell = isinstance(cmd, basestring), bufsize = bufsize, stdin = PIPE, stdout = PIPE, stderr = PIPE, close_fds = True)
  775.             return (p.stdin, p.stdout, p.stderr)
  776.  
  777.         __all__.append('popen3')
  778.     
  779.     if not _exists('popen4'):
  780.         
  781.         def popen4(cmd, mode = 't', bufsize = -1):
  782.             """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
  783.             may be a sequence, in which case arguments will be passed directly to
  784.             the program without shell intervention (as with os.spawnv()).  If 'cmd'
  785.             is a string it will be passed to the shell (as with os.system()). If
  786.             'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
  787.             file objects (child_stdin, child_stdout_stderr) are returned."""
  788.             import warnings
  789.             msg = 'os.popen4 is deprecated.  Use the subprocess module.'
  790.             warnings.warn(msg, DeprecationWarning, stacklevel = 2)
  791.             import subprocess
  792.             PIPE = subprocess.PIPE
  793.             p = subprocess.Popen(cmd, shell = isinstance(cmd, basestring), bufsize = bufsize, stdin = PIPE, stdout = PIPE, stderr = subprocess.STDOUT, close_fds = True)
  794.             return (p.stdin, p.stdout)
  795.  
  796.         __all__.append('popen4')
  797.     
  798.  
  799. import copy_reg as _copy_reg
  800.  
  801. def _make_stat_result(tup, dict):
  802.     return stat_result(tup, dict)
  803.  
  804.  
  805. def _pickle_stat_result(sr):
  806.     (type, args) = sr.__reduce__()
  807.     return (_make_stat_result, args)
  808.  
  809.  
  810. try:
  811.     _copy_reg.pickle(stat_result, _pickle_stat_result, _make_stat_result)
  812. except NameError:
  813.     pass
  814.  
  815.  
  816. def _make_statvfs_result(tup, dict):
  817.     return statvfs_result(tup, dict)
  818.  
  819.  
  820. def _pickle_statvfs_result(sr):
  821.     (type, args) = sr.__reduce__()
  822.     return (_make_statvfs_result, args)
  823.  
  824.  
  825. try:
  826.     _copy_reg.pickle(statvfs_result, _pickle_statvfs_result, _make_statvfs_result)
  827. except NameError:
  828.     pass
  829.  
  830. if not _exists('urandom'):
  831.     
  832.     def urandom(n):
  833.         '''urandom(n) -> str
  834.  
  835.         Return a string of n random bytes suitable for cryptographic use.
  836.  
  837.         '''
  838.         
  839.         try:
  840.             _urandomfd = open('/dev/urandom', O_RDONLY)
  841.         except (OSError, IOError):
  842.             raise NotImplementedError('/dev/urandom (or equivalent) not found')
  843.  
  844.         
  845.         try:
  846.             bs = ''
  847.             while n - len(bs) >= 1:
  848.                 bs += read(_urandomfd, n - len(bs))
  849.         finally:
  850.             close(_urandomfd)
  851.  
  852.         return bs
  853.  
  854.  
  855.